package com.basker.pisces.domain.command.option;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.util.ObjectUtils;

import com.basker.pisces.domain.command.meta.SaveCommand;

/**
 * {@link SaveCommand}执行的选项
 *
 * @author hangwen
 */
public class SaveCommandExecuteOption extends CommandExecuteOption {
    private boolean disableStringValueLengthValidator = false;
    private boolean disableRequiredPropertyValidator = false;
    private Set<String> ignoredRequiredProperties;

    /**
     * 添加忽略必填校验的属性
     *
     * @param ignoredRequiredProperties
     */
    public void addIgnoredRequiredProperties(String... ignoredRequiredProperties) {
        if (ObjectUtils.isEmpty(ignoredRequiredProperties)) {
            return;
        }

        List<String> list = Arrays.asList(ignoredRequiredProperties);

        if (this.ignoredRequiredProperties == null) {
            this.ignoredRequiredProperties = new HashSet<>(list);
        } else {
            this.ignoredRequiredProperties.addAll(list);
        }
    }

    /**
     * 获取忽略必填校验的属性
     *
     * @return
     */
    public Set<String> getIgnoredRequiredProperties() {
        return ignoredRequiredProperties != null ? ignoredRequiredProperties : Collections.emptySet();
    }

    /**
     * 执行{@link SaveCommand}时候，可以通过当前参数禁用必填校验，当外部需要保存一个partbean的时候会很有用
     *
     * @return
     */
    public boolean isDisableRequiredPropertyValidator() {
        return disableRequiredPropertyValidator;
    }

    /**
     * 执行{@link SaveCommand}时候，可以通过当前参数禁用字符长度校验
     *
     * @return
     */
    public boolean isDisableStringValueLengthValidator() {
        return disableStringValueLengthValidator;
    }

    public void setDisableRequiredPropertyValidator(boolean disableRequiredPropertyValidator) {
        this.disableRequiredPropertyValidator = disableRequiredPropertyValidator;
    }

    public void setDisableStringValueLengthValidator(boolean disableStringValueLengthValidator) {
        this.disableStringValueLengthValidator = disableStringValueLengthValidator;
    }

}
